package common.store.admin.service.impl;

import common.store.admin.dao.ProductDao;
import common.store.admin.dto.Product;
import common.store.admin.service.AdminProductService;
import common.store.admin.vo.QueryVo;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

public class AdminProductServiceImpl implements AdminProductService{

    private ProductDao productDao;

    @Override
    public Product getProductByPid(String pid) {
        return ProductDao.getProductByPid(pid);
    }

    public AdminProductServiceImpl(){
        productDao = new ProductDao();
    }
    @Override
    public List<Product> getProductList(QueryVo qv) {
        return productDao.getProductList(qv);
    }

    @Override
    public Integer updateProduct(Map<String, String[]> parameterMap) {
        Product product = new Product();
        try {
            BeanUtils.populate(product , parameterMap);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        return ProductDao.updateProduct(product);

    }

    @Override
    public Integer DelProductByPid(String pid) {
        return productDao.delProduct(pid);
    }


}
